﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Worms3003
{
    public class Birds
    {
        #region atributos
        Texture2D textura;
        public int larguraImagem, alturaImagem, x, y, largura, altura, xCut, yCut, intervalo, totalFramesX, totalFramesY;
        float rotação;
        Vector2 velocidade;
        SpriteEffects efeitos;
        Color cor;
        public Vector2 posicao;
        int timer;
        int frameX, frameY;
        #endregion

        public Vector2 positions
        {
            get { return this.posicao; }
            set { this.posicao = value; }
        }

        public Birds(Texture2D texture, int widthImage, int heightImage, int X, int Y, int width, int height, int XCut,
                     int YCut, int interval, int TotalFramesX, int TotalFramesY, float rotation, Vector2 speed, 
                     SpriteEffects spriteEffects, Color color)
        {
            #region construtor da classe
            textura = texture;
            larguraImagem = widthImage;
            alturaImagem = heightImage;
            x = X;
            y = Y;
            largura = width;
            altura = height;
            xCut = XCut;
            yCut = YCut;
            intervalo = interval;
            totalFramesX = TotalFramesX;
            totalFramesY = TotalFramesY;
            rotação = rotation;
            velocidade = speed;
            efeitos = spriteEffects;
            cor = color;
            frameX = 0;
            frameY = 0;
            #endregion
        }

        public void Update(GameTime gameTime)
        {
            timer += gameTime.ElapsedGameTime.Milliseconds;

            if (timer >= intervalo)
            {
                timer = 0;

                if(frameX <= (totalFramesX - 1))
                    frameX++;

                else
                    frameX = 0;

                if (frameY <= (totalFramesY - 1))
                    frameY++;

                else
                    frameY = 0;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(textura, new Rectangle((int)positions.X, (int)positions.Y, larguraImagem, alturaImagem), new Rectangle(x + frameX * xCut, y + frameY * yCut, largura, altura), cor, rotação, Vector2.Zero, efeitos, 0f);                
        }
    }
}
